//
//  DSPTabBarController.swift
//  SWweibo
//
//  Created by 杜守鹏 on 15/12/26.
//  Copyright © 2015年 杜守鹏. All rights reserved.
//

import UIKit

class DSPTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let tabbar = DSPtabBar()
        setValue(tabbar, forKeyPath: "tabBar")
       
        let course = {
            print("didClickPlusButto")
        }
        tabbar.didClickPlusButton = {
            print("haha")
        }
        
      addchildcontrollers()
    }
    
    func addchildcontrollers(){
        addChildViewController(DSPHomeController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(DSPMessageController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(DSPDiscoverController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(DSPMeController(), imageName: "tabbar_profile", title: "我")
    
    }
    
    func addChildViewController (childVc:UIViewController, imageName:String , title:String) {
        childVc.title = title
        childVc.tabBarItem.image = UIImage(named:imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childVc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        //
        var attributesDic = [String:NSObject]()
        attributesDic[NSForegroundColorAttributeName] = UIColor.orangeColor()
        //        let attributesDic = [
        //            NSForegroundColorAttributeName : UIColor.orangeColor()
        //        ]
        //        print(attributesDic)
        childVc.tabBarItem.setTitleTextAttributes(attributesDic, forState: UIControlState.Selected)
        
        addChildViewController(DSPNavigationController(rootViewController: childVc))
    }
}
